package com.example.designpatterns.structural.bridge;

/**
 * 客户端代码（具体使用）
 *
 * @author scott
 */
public class Client {

    /**
     * 测试桥接模式在数据库驱动程序设计中的应用
     */
    public static void main(String[] args) {
        // 使用MySQL数据库驱动连接MySQL数据库
        DatabaseDriver mysqlDriver = new MySQLDriver();
        DatabaseConnector mysqlConnector = new DatabaseConnector(mysqlDriver);
        mysqlConnector.connectToDatabase("jdbc:mysql://localhost:3306/mydb", "root", "password");
        mysqlConnector.executeQuery("SELECT * FROM users");
        mysqlConnector.executeStatement("INSERT INTO users (name, age) VALUES ('John', 30)");

        // 使用PostgreSQL数据库驱动连接PostgreSQL数据库
        DatabaseDriver postgreSqlDriver = new PostgreSQLDriver();
        DatabaseConnector postgreSqlConnector = new DatabaseConnector(postgreSqlDriver);
        postgreSqlConnector.connectToDatabase("jdbc:postgresql://localhost:5432/mydb", "postgres", "password");
        postgreSqlConnector.executeQuery("SELECT * FROM products");
        postgreSqlConnector.executeStatement("UPDATE products SET price = 100 WHERE id = 1");
    }

}
